// 个人中心相关 Mock 数据

import type { UserProfile, TopicWord, InterestTrendPoint, Bookmark } from '@/types/profile';
import type { ApiResponse } from '@/types/api';

// 模拟延迟
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

// 模拟关键词词云数据
const mockTopicCloud: TopicWord[] = [
  { text: '高血压', value: 45, color: '#409EFF' },
  { text: '睡眠', value: 38, color: '#67C23A' },
  { text: '营养', value: 32, color: '#E6A23C' },
  { text: '运动', value: 28, color: '#F56C6C' },
  { text: '心理健康', value: 25, color: '#909399' },
  { text: '糖尿病', value: 22, color: '#409EFF' },
  { text: '减肥', value: 20, color: '#67C23A' },
  { text: '饮食', value: 18, color: '#E6A23C' },
  { text: '焦虑', value: 15, color: '#F56C6C' },
  { text: '锻炼', value: 13, color: '#909399' },
  { text: '头痛', value: 12, color: '#409EFF' },
  { text: '压力', value: 10, color: '#67C23A' },
  { text: '失眠', value: 9, color: '#E6A23C' },
  { text: '维生素', value: 8, color: '#F56C6C' },
  { text: '体检', value: 7, color: '#909399' }
];

// 模拟兴趣趋势数据
const mockInterestTrend: InterestTrendPoint[] = [
  { date: '2025-10-01', nutrition: 5, mental: 3, exercise: 2, general: 4 },
  { date: '2025-10-05', nutrition: 7, mental: 4, exercise: 3, general: 5 },
  { date: '2025-10-10', nutrition: 6, mental: 6, exercise: 4, general: 6 },
  { date: '2025-10-15', nutrition: 8, mental: 5, exercise: 5, general: 7 },
  { date: '2025-10-20', nutrition: 9, mental: 7, exercise: 6, general: 8 },
  { date: '2025-10-25', nutrition: 10, mental: 8, exercise: 7, general: 9 },
  { date: '2025-10-30', nutrition: 12, mental: 9, exercise: 8, general: 10 }
];

// 模拟收藏数据
const mockBookmarks: Bookmark[] = [
  {
    id: 'bm_001',
    title: '如何科学降血压',
    content: '降低血压需要从饮食、运动、作息等多方面入手。建议减少盐分摄入，每天不超过6克...',
    source: 'AI助手推荐',
    category: '心血管健康',
    createdAt: Date.now() - 86400000 * 5,
    tags: ['高血压', '饮食', '运动']
  },
  {
    id: 'bm_002',
    title: '改善睡眠质量的10个方法',
    content: '良好的睡眠对健康至关重要。以下是10个改善睡眠的科学方法：1. 保持规律作息...',
    source: 'AI助手推荐',
    category: '生活方式',
    createdAt: Date.now() - 86400000 * 3,
    tags: ['睡眠', '作息', '健康']
  },
  {
    id: 'bm_003',
    title: '维生素B族的作用与补充',
    content: '维生素B族包括B1、B2、B6、B12等，对神经系统、能量代谢都很重要...',
    source: 'AI助手推荐',
    category: '营养健康',
    createdAt: Date.now() - 86400000 * 1,
    tags: ['营养', '维生素', '补充']
  },
  {
    id: 'bm_004',
    title: '焦虑情绪的自我调节',
    content: '面对焦虑，我们可以通过深呼吸、正念冥想、适度运动等方式进行自我调节...',
    source: 'AI助手推荐',
    category: '心理健康',
    createdAt: Date.now() - 86400000 * 7,
    tags: ['心理', '焦虑', '压力']
  }
];

/**
 * Mock 获取用户档案
 */
export const mockGetUserProfile = async (): Promise<ApiResponse<UserProfile>> => {
  await delay(800);

  const profile: UserProfile = {
    userId: 'user_001',
    username: 'test_user',
    avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    joinDate: Date.now() - 86400000 * 90, // 90天前加入
    totalSessions: 45,
    totalMessages: 230,
    topicCloud: mockTopicCloud,
    interestTrend: mockInterestTrend,
    bookmarks: mockBookmarks
  };

  return {
    code: 200,
    data: profile,
    message: '获取成功'
  };
};

/**
 * Mock 添加收藏
 */
export const mockAddBookmark = async (bookmark: Omit<Bookmark, 'id' | 'createdAt'>): Promise<ApiResponse<Bookmark>> => {
  await delay(500);

  const newBookmark: Bookmark = {
    id: `bm_${Date.now()}`,
    ...bookmark,
    createdAt: Date.now()
  };

  mockBookmarks.unshift(newBookmark);

  return {
    code: 200,
    data: newBookmark,
    message: '收藏成功'
  };
};

/**
 * Mock 删除收藏
 */
export const mockDeleteBookmark = async (bookmarkId: string): Promise<ApiResponse<null>> => {
  await delay(300);

  const index = mockBookmarks.findIndex(b => b.id === bookmarkId);
  if (index === -1) {
    return {
      code: 404,
      data: null,
      message: '收藏不存在'
    };
  }

  mockBookmarks.splice(index, 1);

  return {
    code: 200,
    data: null,
    message: '删除成功'
  };
};

/**
 * Mock 获取收藏列表
 */
export const mockGetBookmarks = async (category?: string): Promise<ApiResponse<{ bookmarks: Bookmark[] }>> => {
  await delay(500);

  let filteredBookmarks = mockBookmarks;
  
  if (category) {
    filteredBookmarks = mockBookmarks.filter(b => b.category === category);
  }

  return {
    code: 200,
    data: {
      bookmarks: filteredBookmarks
    },
    message: '获取成功'
  };
};